#include "common.hpp"
#include "Log.hpp"
#include "TcpServer.hpp"
#include "InetAddr.hpp"
#include "Dict.hpp"
#include "Command.hpp"
using namespace LogModule;

void Usage(std::string str)
{
    LOG(LogLevel::FATAL) << "you should enter : " << str << "target port" ;
}

int main(int args, char* argv[])
{
    if(args != 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERROR);
    }
    Enable_Console_Log_Strategy();

    u_int16_t port = std::stoi(argv[1]);//将字符串转为整型

    //Dict dir;
    //dir.DictInit();
    CMD com;

    std::unique_ptr<TcpServer> Tcps = std::make_unique<TcpServer>(port,[&com](const std::string& cmd, InetAddr& peer)
        {
            return com.Excute(cmd,peer);
        });

    Tcps->Init();
    Tcps->Start();

    return 0;
}